Repository navigation
fix: bin GPU heatmap in Web Mercator so heat lines up with airports (#15) - #21
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AELE7jB1i3uqqrHu3SjJjf
…ment (#15) The accumulate shader bins latitude linearly over [-90, 90] while the BitmapLayer stretches the image linearly in Mercator Y over +/-85.051129, so hot spots drift north away from airports. These tests pin a shared projection helper, its generated WGSL, and the layer bounds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AELE7jB1i3uqqrHu3SjJjf
…15) The accumulate shader mapped latitude linearly over [-90, 90], but the BitmapLayer draws the image linearly in Mercator Y over +/-85.051129, so heat drifted north of airports at mid and high latitudes. A new heatmapProjection module owns the latitude limit, grid size, bounds, and lat-to-row formula, and generates the shader's binning WGSL from those constants so the two cannot drift apart again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AELE7jB1i3uqqrHu3SjJjf
The WGSL lonToCol and latToRow bodies restate the formulas in shader syntax, and no test ran them, so a broken shader formula stayed green. The new test translates the generated WGSL into JS with a strict translator that rejects unknown tokens, then checks it against the JS helpers at reference points, past the Mercator and polar limits, and over full lat and lon sweeps. The plan now records this coverage and describes the row clamping as the code does it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AELE7jB1i3uqqrHu3SjJjf
In float64 the south limit gives a row fraction just under 1, so the shader's row clamp was never exercised; on the GPU, in f32, it is exactly 1 and the clamp is what keeps the row inside the grid. The translator is now a small parser that can emit f32-rounded JS, and new tests assert rows and columns stay in range, extremes land on the edge rows and columns, and sweeps stay within one cell of the JS helpers. Each translator rejection test now asserts the error for its own path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AELE7jB1i3uqqrHu3SjJjf
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AELE7jB1i3uqqrHu3SjJjf
Closed
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The GPU heatmap's accumulate shader binned airports into an equirectangular grid (
row = (90 - lat) / 180 * 512), but the deck.glBitmapLayerdraws that image stretched linearly in Web Mercator Y between +/-85.051129. That pushed heat toward the poles: an airport at 60N drew near 76N.The shader now bins latitude in Web Mercator Y, clamped to +/-85.051129, and the bitmap keeps its Mercator bounds. A new helper module,
src/layers/heatmapProjection.js, is the one source for the latitude limit, the grid size, the lat/lon-to-cell formulas andHEATMAP_BOUNDS. The shader's WGSLlonToCol/latToRoware generated from its constants, andbuildLayerstakes its bounds from it.I chose not to use
_imageCoordinateSystem: COORDINATE_SYSTEM.LNGLATwith[-180, -90, 180, 90]bounds. In deck.gl 9.4.1 that prop is experimental. Its fragment shader clamps latitude to +/-89.9, while quad corners at +/-90 project to infinite Mercator Y. No unit test can pin its behavior in the non-interleaved overlay.Unchanged: the color ramp, the run-once behavior, buffer lifetimes, the COLORIZE shader, and the earlier a11y, layout, contrast, benchmark and RENDER work.
Plan
docs/plans/2026-11-07-issue-15-gpu-heatmap-misregistered.md, committed at 8071492 before any code. Revised during the work:Test evidence
Gate on 7589af6 (d710501 changes only the plan doc), all exit 0:
npm ci: 0 vulnerabilitiesnpm run lint: cleannpm test: 32 files, 290 tests passednpm run build: built; the existing chunk-size warning remainsnpm audit --omit=dev --audit-level=high: 0 vulnerabilitiesNew tests:
src/layers/heatmapProjection.test.jssweeps latitudes from -80 to 80. For each, the row the helper picks, drawn linearly in Mercator Y overHEATMAP_BOUNDS, covers that latitude. It also checks reference points and clamping at +/-85.051129, +/-90 and beyond.src/layers/heatmapProjection.wgsl.test.jstranslates the generated WGSL to JS and checks it against the JS helpers. In float64 the results must match exactly. In f32 emulation, rows and columns must stay in the grid, extreme latitudes must land on the first or last row, and sweeps must stay within one cell. Each of these mutations makes the test fail:/ 2.0to* 2.0, dropping1.0 -, dropping+ 180.0, and changing the row clamp511.0to512.0or0.0to-5.0.src/layers/index.test.js: the heatmap layer usesHEATMAP_BOUNDSand sets no_imageCoordinateSystem.src/hooks/useGPUHeatmap.test.js: the shader contains the generated binning code, and the old(90.0 - lat) / 180.0is gone.Live drive, Playwright Chromium with a SwiftShader WebGPU adapter (
--enable-unsafe-webgpu --use-webgpu-adapter=swiftshader), HEATMAP and AIRPORTS on:map.project([lon, lat])and the drawn center of the airport's row is 8.81 px, against a 22.6 px cell. The old code was off by up to 1443 px.Review findings
First round: three Claude finders (Bugs/Compliance, Security, outside-the-diff) and two Fable finders (Bugs/Compliance, edge cases).
* (1 / 2)would pass the test but be integer division on the GPU. This can't happen today because the generator writes every literal with a decimal point. Raised by Claude in the second delta round. I left it rather than start another fix round.u32()throws on negative values, which is stricter than WGSL's saturation.HEATMAP_BOUNDSis a mutable array;Object.freezewould protect it.useAirportsdrops non-finite coordinates.Docs reconciled
Closes #15
🤖 Generated with Claude Code
https://claude.ai/code/session_01AELE7jB1i3uqqrHu3SjJjf